package edu.zut.main.thread;

public class ThreadDemo2 {

    public static void main(String[] args) {
        ImgThread imgThread1 = new ImgThread("https://img1.baidu.com/it/u=172337203,4011950556&fm=26&fmt=auto&gp=0.jpg", "1.jpg");
        ImgThread imgThread2 = new ImgThread("https://img1.baidu.com/it/u=2729200364,1701331398&fm=26&fmt=auto&gp=0.jpg", "2.jpg");
        ImgThread imgThread3 = new ImgThread("https://img1.baidu.com/it/u=2397343483,1770497010&fm=26&fmt=auto&gp=0.jpg", "3.jpg");

        Thread thread = new Thread(imgThread1, "下载线程1");
        Thread thread1 = new Thread(imgThread2, "下载线程2");
        Thread thread3 = new Thread(imgThread3);
        thread.start();
        thread1.start();
        thread3.start();

    }

}

/**
 * 多线程的实现
 * 利用Runnable接口进行实现
 * 将线程任务与线程对象进行分离
 *
 */
class ImgThread implements Runnable{

    private String url;
    private String pathName;

    public ImgThread(String url, String pathName) {
        this.url = url;
        this.pathName = pathName;
    }

    @Override
    public void run() {
        new ImgDown().download(url,pathName);
        System.out.println("下载了"+pathName);
    }
}


